<?php
/**
 *用户统计
 * wsl
 * 2022/7.24
 */
namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Http\Serve\Es;
use App\Http\Service\api\UserStatisticsService;
use App\Http\Service\Redisd;
use App\Repository\RepositoryInterface\UserLoginInterface;
use App\Repository\RepositoryInterface\UserStatisticisInterface;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class UserStatisticsController extends Controller
{
    protected $userstatistics;

    public function __construct(UserStatisticisInterface $userstatistics){
        $this->userstatistics = $userstatistics;
    }

    /**
     * @return array
     * 用户信息
     */
    public function userMessage()
    {
        try {
       $user_message = $this->userstatistics->userMessage();
        return ['code'=>20000,'msg'=>'success','data'=>$user_message];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return array
     * 用户id获取
     */
    public function searchUser(Request $request)
    {
        try {
        $user_name = $request->input('user_names');
        $user_name_message = $this->userstatistics->searchUser($user_name);
        return ['code'=>20000,'msg'=>'success','data'=>$user_name_message];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @return mixed
     * 用户新增统计
     */
    public function addUserStatistics()
    {
        try {
        $user_add_statistics = UserStatisticsService::UserAddStatistics();
        return ['code'=>20000,'msg'=>'success','data'=>$user_add_statistics];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @return mixed
     * 用户新增总数统计
     */
    public function addUserStatisticsCount()
    {
        try {
        $user_count = $this->userstatistics->UserAddStatisticsCount();
        return ['code'=>20000,'msg'=>'success','data'=>$user_count];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return int|mixed|string
     * 用户累计充值
     */
    public function userRecharge(Request $request)
    {
        try {
            $user_id = $request->input('user_id');
            $user_recharge = $this->userstatistics->userRecharge($user_id);
            $user_recharge_reg = UserStatisticsService::userRecharge($user_recharge);
            return ['code'=>20000,'msg'=>'success','data'=>$user_recharge_reg];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return array|string
     * 用户充值记录
     */
    public function userRechargeRecording(Request $request)
    {
        try {
            $user_id = $request->input('user_id');
            $user_recharge = $this->userstatistics->userRecharge($user_id);
            $user_recharge_reg = UserStatisticsService::userRechargeRecording($user_recharge);
            return ['code'=>20000,'msg'=>'success','data'=>$user_recharge_reg];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return mixed
     * 用户支付金额统计
     */
    public function paymentStatistics(Request $request)
    {
        try {
        $user_id = $request->input('user_id');
        $user_pay = UserStatisticsService::paymentStatistics($user_id);
        return ['code'=>20000,'msg'=>'success','data'=>$user_pay];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return array
     * 用户累计支付
     */
    public function paymentStatisticsTotal(Request $request)
    {
        try {
        $user_id = $request->input('user_id');
        $user_pay = UserStatisticsService::paymentStatisticsTotal($user_id);
        return ['code'=>20000,'msg'=>'success','data'=>$user_pay];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return int|mixed|string
     * 环比计算
     */
    public function paymentStatisticsChain(Request $request)
    {
        try {
        $user_id = $request->input('user_id');
        $payment_statistics_chain = UserStatisticsService::paymentStatisticsChain($user_id);
        return ['code'=>20000,'msg'=>'success','data'=>$payment_statistics_chain];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @return array|string
     * 用户充值排行榜
     */
    public function userRechargeList()
    {
        try {
            $user_message = $this->userstatistics->userMessage();
            return ['code'=>20000,'msg'=>'success','data'=>UserStatisticsService::userRechargeList($user_message)];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return mixed
     * 用户详情
     */
    public function userDetail(Request $request)
    {
        try {
            $uid = $request->input('user_id');
            $user_detail = $this->userstatistics->userDetail($uid);
            return ['code'=>20000,'msg'=>'success','data'=>$user_detail];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return string
     * 轮播图
     */
    public function carouselDiagram(Request $request)
    {
        try {
            $goods_id = $request->input('goods_id');
            $goods_carousel_diagram = $this->userstatistics->carouselDiagram($goods_id);
            return ['code'=>20000,'msg'=>'success','data'=>$goods_carousel_diagram];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @return mixed|string
     * 更多优惠券
     */
    public function couponsList()
    {
       try{
           $coupon_list = $this->userstatistics->couponsList();
           return ['code'=>20000,'msg'=>'success','data'=>$coupon_list];
       }catch (ValidationException $validationException){
           return $validationException->getFile();
       }
    }

    /**
     * @param Request $request
     * @return mixed|string
     * 领取优惠券
     */
    public function couponCollection(Request $request)
    {
        try {
            $uid = $request->input('user_id');
            $coupon_id = $request->input('coupon_id');
            $coupon_collection = $this->userstatistics->couponCollection($uid,$coupon_id);
            return ['code'=>20000,'msg'=>'success','data'=>$coupon_collection];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return mixed|string
     * 优惠券列表
     */
    public function meCoupon(Request $request)
    {
        try {
            $uid = $request->input('user_id');
            $me_coupon = $this->userstatistics->meCoupon($uid);
            return ['code'=>20000,'msg'=>'success','data'=>$me_coupon];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }

    /**
     * @param Request $request
     * @return array|string
     * 秒杀商品状态
     */
    public function spikeStatus(Request $request)
    {
        try {
            $goods_id = $request->input('goods_id');
            $status = $this->userstatistics->spikeStatusQuery($goods_id);
            $status = UserStatisticsService::spikeStatus($status->status);
            $update_status_reg = $this->userstatistics->spikeStatus($goods_id,$status);
            return ['code'=>20000,'msg'=>'success','data'=>$update_status_reg];
        }catch (ValidationException $validationException){
            return $validationException->getFile();
        }
    }
}
